// Shared variables - available in all effects
// These don't need to be set manually
float2 PixelSize;
float4x4 InvViewProj;
float NearClipPlane;
float FarClipPlane;
float3 CameraPosition;

float4x4 xWorldViewProjection;


Texture xColorTexture;
sampler COLORSampler = sampler_state { texture = <xColorTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};

Texture xBlurTexture;
sampler BLURSampler = sampler_state { texture = <xBlurTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};

Texture xDepthTexture;
sampler DEPTHSampler = sampler_state { texture = <xDepthTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};




// Depth of field shader - combines blur with color based on DOF params
float4 DofShader(float2 texCoord : TEXCOORD0) : COLOR
{
	// Get the depth
	float depth = tex2D(DEPTHSampler, texCoord).x;

	// Get the color and blur color
	float4 baseColor = tex2D(COLORSampler, texCoord);
	float4 blurColor = tex2D(BLURSampler, texCoord);


	// Get color	
	float4 returnColor = lerp(baseColor, blurColor, depth);
	//float4 returnColor = (blurColor, 1, 1, 1);
	// Return the color
	return returnColor;
}



technique DepthOfField
{
    pass Pass0
    {
		pixelShader = compile ps_2_0 DofShader();
    }
}




//DEPTHMAP GENERATION

 struct DMapVertexToPixel
 {
     float4 Position     : POSITION;
     float4 Position2D    : TEXCOORD0;
 };
 
 struct DMapPixelToFrame
 {
     float4 Color : COLOR0;
 };
 
 DMapVertexToPixel DepthMapVertexShader( float4 inPos : POSITION)
 {
     DMapVertexToPixel Output = (DMapVertexToPixel)0;
 
     Output.Position = mul(inPos, xWorldViewProjection);
     Output.Position2D = Output.Position;
 
     return Output;
 }
 
 DMapPixelToFrame DepthMapPixelShader(DMapVertexToPixel PSIn)
 {
     DMapPixelToFrame Output = (DMapPixelToFrame)0;   
              
	 Output.Color = 0;  
	
     return Output;
 }
 
 technique DepthMap
 {
     pass Pass0
     {
         VertexShader = compile vs_2_0 DepthMapVertexShader();
         PixelShader = compile ps_2_0 DepthMapPixelShader();
     }
 }